package cn.j229.bug.zhongxuan.eureka_service_feign_hystrix.service;

import cn.j229.bug.zhongxuan.eureka_service_feign_hystrix.proxy.FeignClientHandler;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author smile_ZhongXuan
 * @Date 2020/10/29 16:06
 * @Version 1.0
 */
@Service
public class UserHandlerService {

    @Resource
    FeignClientHandler feignClientHandler = null;

    // 通过feign调用服务模块，如果触发熔断机制，则会调用此注解fallbackMethod定义的方法
    @HystrixCommand(fallbackMethod = "checkError")
    public Map get() {
        return feignClientHandler.handler();
    }

    public Map checkError() {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
}
